<!DOCTYPE html>

<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>元素的属性</title>
    </head>
    <body>

        <script type="text/javascript">
        // IIFE : Immediately-invoked function expression
        // ( x => console.log( x ) )( 250 );
        ( ()=>{
            // document 是一个特殊的 Node
            const root = document.getRootNode();
            console.log( root.nodeType , root.nodeName , root.nodeValue );
            if( root.hasChildNodes() ){
                let childs =  root.childNodes ; // childs 是 NodeList
                for( let i = 0 ; i < childs.length ; i++ ){
                    let n = childs[ i ] ;
                    console.log( n.nodeType , n.nodeName , n.nodeValue );
                    // 判断 n 是否是个 Element
                    if( n.nodeType === Node.ELEMENT_NODE ){
                        // 如果元素有属性
                        if( n.hasAttributes ){
                            let names = n.getAttributeNames();
                            names.forEach( name => {
                                let an = n.getAttributeNode( name );
                                console.log( an.nodeType , an.nodeName , an.nodeValue );
                            } );
                        }
                    }
                }
            }


        } )();
        </script>
        
    </body>
</html>